﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

using Obsidian.Utils;

namespace Obsidian.Config
{

    public class CacheConfig
    {
        private static DateTime modified = DateTime.MinValue;
        private static FileCacheInfo fileCache;

        public static FileCacheInfo FileCache
        {
            get
            {
                CheckForChanged();
                return fileCache;
            }
        }

        private static void CheckForChanged()
        {
            if (AppConfig.CheckForChanged() || !AppConfig.Modified.Equals(modified))
            {
                GetCacheInfos();
                modified = AppConfig.Modified;
            }
        }

        private static void GetCacheInfos()
        {
            XmlDocument xmlDoc = AppConfig.GetXml();
            string val;

            fileCache = new FileCacheInfo();
            fileCache.SetPath("/cache");
            XmlNode node = xmlDoc.SelectSingleNode("appConfig/cache/fileCache");
            if (XmlUtil.TryGetAttrValue(node, "path", out val))
                fileCache.SetPath(val);


        }

        public class FileCacheInfo
        {
            private string _path;

            public string Path
            {
                get { return this._path; }
            }

            internal void SetPath(string path)
            {
                this._path = path;
            }
        }

    }

}
